package com.jiangyg.mall.order.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.order.dto.PaymentInfoDTO;
import com.jiangyg.mall.order.service.PaymentInfoService;
import com.jiangyg.mall.order.vo.PaymentInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：支付信息表控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:36:28
 */
@RestController
@RequestMapping("/order/paymentInfo")
public class PaymentInfoController {

    /**
     * 支付信息表接口
     */
    private final PaymentInfoService paymentInfoService;

    @Autowired
    public PaymentInfoController(PaymentInfoService paymentInfoService) {
        this.paymentInfoService = paymentInfoService;
    }

    /**
     * 功能描述：支付信息表分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页支付信息表
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<PaymentInfoVO>> select(HttpServletRequest request, @RequestBody Pagination<PaymentInfoVO> pagination) throws Exception {
        return Result.ok(paymentInfoService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改支付信息表
     *
     * @param request 请求
     * @param dto     支付信息表
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated PaymentInfoDTO dto) throws Exception {
        return Result.saveOrUpdate(paymentInfoService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取支付信息表
     *
     * @param request 请求
     * @param paymentInfoId  支付信息表ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<PaymentInfoVO> info(HttpServletRequest request, @RequestParam(name = "paymentInfoId") Long paymentInfoId) throws Exception {
        return Result.ok(paymentInfoService.selectById(paymentInfoId));
    }

    /**
     * 功能描述：删除支付信息表
     *
     * @param request 请求
     * @param paymentInfoIds 批量删除的支付信息表ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "paymentInfoIds") List<Long> paymentInfoIds) {
        return Result.delete(paymentInfoService.delete(paymentInfoIds));
    }

}
